/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Controladores;

import java.util.List;
import javax.persistence.EntityManagerFactory;
import Clases.Nota;
import javax.persistence.EntityManager;
/**
 *
 * @author PaBLo
 */
public class NotaPersonalizado extends NotaJpaController{
    public NotaPersonalizado(EntityManagerFactory emf){
        super(emf);
    }
    public List<Nota> pTodasLasNotas(){
        EntityManager em = super.getEntityManager();
        return em.createQuery("select n from Nota n").getResultList();
    }
    public int pUltimoId(){
        EntityManager em = super.getEntityManager();
        List<Nota> todos = em.createQuery("select n from Nota n").getResultList();
        if(todos.isEmpty()){
            return 0;
        }else{
            Nota ultimo = todos.get(todos.size()-1);
            return ultimo.getIdNota();
        }
    }
    public Nota pBuscarxIndice(int ind){
        EntityManager em = super.getEntityManager();
        List<Nota> todos = em.createQuery("select n from Nota n").getResultList();
        Nota nt=todos.get(todos.size()-1);;
        int cont=0;
        for(Nota t:todos){
            if(cont==ind){
                nt=t;
            }
            cont++;
        }
        return nt;
    }
}
